package util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.concerneyes.CEApp;
import com.concerneyes.R;
import com.concerneyes.health.EditOptometryData;
import com.concerneyes.mine.TabActivity.serviceCentre.DetailActivity;

import common.AbsActivity;
import common.WebViewActivity;

/**
 * 
 *activity的相关工作
 */
public class ActivityUtil {

    public static void setIntent(Context context, Class<?extends AbsActivity> aClass,Bundle bundle){
        Intent intent = new Intent();
        intent.setClass(context, aClass);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }
    public static void detailIntent(Context context,int itemId,String title,String content){
        Bundle bundle = new Bundle();
        bundle.putString("activityId",String.valueOf(itemId));
        bundle.putString("title",title);
        bundle.putString("content",content);
        Intent intent = new Intent();
        intent.setClass(context, WebViewActivity.class);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }
    public static void setIntentForResult(Activity activity, Class<?extends AbsActivity> aClass,Bundle bundle,int code){
        Intent intent = new Intent();
        intent.setClass(activity, aClass);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        activity.startActivityForResult(intent,code);
    }
    public static void setIntentForEdit(Context context, Class<?extends AbsActivity> aClass,
                                          String manId,String showStyle,String id){
        Bundle bundle = new Bundle();
        bundle.putString("manId", manId);
        bundle.putString("showStyle", showStyle);
        bundle.putString("id", id);
        setIntent(context, EditOptometryData.class, bundle);
    }

    /**
     * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
     */
    public static int dip2px(float dpValue) {
        final float scale = CEApp.getInstance().getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    /**
     * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
     */
    public static int px2dip( float pxValue) {
        final float scale =  CEApp.getInstance().getResources().getDisplayMetrics().density;
        return (int) (pxValue / scale + 0.5f);
    }

    /**
     * 将px值转换为sp值，保证文字大小不变 
     *
     * @param pxValue
     *            （DisplayMetrics类中属性scaledDensity） 
     * @return
     */
    public static int px2sp( float pxValue) {
        final float fontScale = CEApp.getInstance().getResources().getDisplayMetrics().scaledDensity;
        return (int) (pxValue / fontScale + 0.5f);
    }

    /**
     * 将sp值转换为px值，保证文字大小不变 
     *
     * @param spValue
     *            （DisplayMetrics类中属性scaledDensity） 
     * @return
     */
    public static int sp2px( float spValue) {
        final float fontScale = CEApp.getInstance().getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }
}
